#include "txt.h"

#include <QFile>
#include <QTextStream>
#include <QTextCodec>
#include <QFileInfo>

#include "../paragraph/text.h"

namespace Book
{
namespace Format
{

void TXT::ProcessBookFile ()
{
    QFile inputFile(GetFileInfo().GetFileName());

    QTextStream inputStream;
    //inputStream.setCodec(QTextCodec::codecForName(m_BookData->GetFileInfo().GetEncoding()));
    inputStream.setDevice(&inputFile);

    Book::Description description (QFileInfo(GetFileInfo().GetFileName()).baseName(), QString());
    m_BookData->SetDescription(description);

    inputFile.open(QIODevice::ReadOnly);
    foreach (QString currTxt, inputStream.readAll().split(QRegExp("\r\n|\n")))
        m_BookData->AddParagraph(
            Paragraph::SharedPtr(
                new Paragraph::Text(QTextCharFormat(), currTxt)));
}


}
}

